﻿@model HZY.Admin.Model.CodeGenerationModel
@{
    var className = Model.TableName;
}
<pre>
/*
 * *******************************************************
 *
 * 作者：hzy
 *
 * 开源地址：https://gitee.com/hzy6
 *
 * *******************************************************
 */
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using HZY.Admin.Core;
using HZY.Admin.Services;
using HZY.Framework.Attributes;
using HZY.Framework.Controllers;
using HZY.Framework.Model;
using HZY.Repository.Attributes;
using HZY.Repository.Domain;
using HZY.Common;
using Microsoft.AspNetCore.Mvc;

namespace HZY.Admin.Controllers
{
    [ControllerDescriptor(MenuId = "请设置菜单Id 系统菜单表中查找")]
    public class @(className)Controller : AdminBaseController<@($"{className}Service")>
    {
        public @(className)Controller(@(className)Service defaultService) 
            : base(defaultService)
        {
        }
        
        /// <summary>
        /// 列表页
        /// </summary>
        /// <returns></returns>
        [ActionDescriptor("Have")]
        [HttpGet(nameof(Index))]
        public IActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 编辑页
        /// </summary>
        /// <param name="id">id</param>
        /// <returns></returns>
        [ActionDescriptor("Have")]
        [HttpGet("Info/{id?}")]
        public IActionResult Info(Guid id)
        {
            return View(id);
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="page">page</param>
        /// <param name="rows">rows</param>
        /// <param name="search">search</param>
        /// <returns></returns>
        [ActionDescriptor("Have")]
        [HttpPost("FindList/{page}/{rows}")]
        public async Task<@("ApiResult")> FindListAsync([FromRoute] int page, [FromRoute] int rows, [FromBody] @(className) search)
        {
            return this.ResultOk(await this.DefaultService.FindListAsync(page, rows, search));
        }

        /// <summary>
        /// 根据id数组删除
        /// </summary>
        /// <param name="ids">ids</param>
        /// <returns></returns>
        [Transactional]
        [HttpPost("DeleteList")]
        public async Task<@("ApiResult")> DeleteListAsync([FromBody] List<@("Guid")> ids)
        {
            await this.DefaultService.DeleteListAsync(ids);
            return this.ResultOk("ok");
        }

        /// <summary>
        /// 查询表单数据
        /// </summary>
        /// <param name="id">id</param>
        /// <returns></returns>
        [HttpGet("FindForm/{id?}")]
        public async Task<@("ApiResult")> FindFormAsync([FromRoute] Guid id)
        {
            return this.ResultOk(await this.DefaultService.FindFormAsync(id));
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="form">form</param>
        /// <returns></returns>
        [Transactional]
        [HttpPost("SaveForm")]
        public async Task<@("ApiResult")> SaveFormAsync([FromBody] @(className) form)
        {
            return this.ResultOk(await this.DefaultService.SaveFormAsync(form));
        }

        /// <summary>
        /// 导出Excel
        /// </summary>
        /// <param name="search"></param>
        /// <returns></returns>
        [ActionDescriptor("GetExcel")]
        [HttpPost("ExportExcel")]
        public async Task<@("FileContentResult")> ExportExcelAsync([FromBody] @(className) search)
            => this.File(await this.DefaultService.ExportExcelAsync(search), Tools.GetFileContentType[".xls"].ToStr(),
                $"{Guid.NewGuid()}.xls");
    }
}
</pre>